package model.entity.product;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import model.entity.OrderDetails;
import model.entity.SalesDetails;

@Entity
@Table(name = "Product")
public class Product {

	private int productId;
	private Category category;
	private Brand brand;
	private String name;
	private String description;
	private int price;
	private boolean avalable;
	private String image;
	private int quantity;
	private List<OrderDetails> orderDetailses = new ArrayList<OrderDetails>(0);
	private Set<Theme> themes = new HashSet<Theme>(0);
	private List<SalesDetails> salesDetailses = new ArrayList<SalesDetails>(0);
	private List<ProductDetails> productDetailses = new ArrayList<ProductDetails>(0);

	public Product() {
	}

	public Product(Category category, Brand brand, String name,
			int price, boolean avalable, int quantity) {
		this.category = category;
		this.brand = brand;
		this.name = name;
		this.price = price;
		this.avalable = avalable;
		this.quantity = quantity;
	}

	public Product(Category category, Brand brand, String name,
			String description, int price, boolean avalable, String image,
			int quantity, List<OrderDetails> orderDetailses,
			Set<Theme> themes, List<SalesDetails> salesDetailses,
			List<ProductDetails> productDetailses) {
		this.category = category;
		this.brand = brand;
		this.name = name;
		this.description = description;
		this.price = price;
		this.avalable = avalable;
		this.image = image;
		this.quantity = quantity;
		this.orderDetailses = orderDetailses;
		this.themes = themes;
		this.salesDetailses = salesDetailses;
		this.productDetailses = productDetailses;
	}

	@Id
	@GeneratedValue(generator = "Product_ID_Gen", strategy = GenerationType.IDENTITY)
	@SequenceGenerator(name = "Product_ID_Gen", sequenceName = "Product_SEQ_ID")
	@Column(name = "ProductID", unique = true, nullable = false)
	public int getProductId() {
		return this.productId;
	}

	public void setProductId(int productId) {
		this.productId = productId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CategoryID", nullable = false)
	public Category getCategory() {
		return this.category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "BrandID", nullable = false)
	public Brand getBrand() {
		return this.brand;
	}

	public void setBrand(Brand brand) {
		this.brand = brand;
	}

	@Column(name = "Name", nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "Description")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "Price", nullable = false)
	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	@Column(name = "Avalable", nullable = false)
	public boolean isAvalable() {
		return this.avalable;
	}

	public void setAvalable(boolean avalable) {
		this.avalable = avalable;
	}

	@Column(name = "Image")
	public String getImage() {
		return this.image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	@Column(name = "Quantity", nullable = false)
	public int getQuantity() {
		return this.quantity;
	}

	public void setQuantity(int quantity) {
		this.quantity = quantity;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
	public List<OrderDetails> getOrderDetailses() {
		return this.orderDetailses;
	}

	public void setOrderDetailses(List<OrderDetails> orderDetailses) {
		this.orderDetailses = orderDetailses;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "products")
	public Set<Theme> getThemes() {
		return this.themes;
	}

	public void setThemes(Set<Theme> themes) {
		this.themes = themes;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
	public List<SalesDetails> getSalesDetailses() {
		return this.salesDetailses;
	}

	public void setSalesDetailses(List<SalesDetails> salesDetailses) {
		this.salesDetailses = salesDetailses;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "product")
	public List<ProductDetails> getProductDetailses() {
		return this.productDetailses;
	}

	public void setProductDetailses(List<ProductDetails> productDetailses) {
		this.productDetailses = productDetailses;
	}

	public void addTheme(Theme theme1) {
		themes.add(theme1);
	}

}
